package service

import (
	"eat-every-day/internal/model"
	"eat-every-day/internal/repository"
	"eat-every-day/internal/routers/api/req_data_model"
	"eat-every-day/pkg/util"
	"time"
)

type IUsersService interface {
	SelectUsersByUsername(username string) (*model.Users, error)
	Create(regInfo *req_data_model.RegisterUsers) error
}

type UsersService struct {
	Repo repository.IUsersRepo
}

func (srv *UsersService) SelectUsersByUsername(username string) (*model.Users, error) {
	return srv.Repo.SelectUsersByUsername(username)
}

func (srv *UsersService) Create(regInfo *req_data_model.RegisterUsers) error {
	users := &model.Users{}

	users.Username = regInfo.Username
	encryptValue := util.Encrypt(regInfo.Password)
	users.Password = encryptValue
	users.Nickname = regInfo.Username
	users.Face = "http://122.152.205.72:88/group1/M00/00/05/CpoxxFw_8_qAIlFXAAAcIhVPdSg994.png"
	users.Birthday = time.Now()
	return srv.Repo.Create(users)
}
